package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RegionQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    RegionMapper regionMapper;

    public void saveOrUpdate(Region region) {
        if (region.getId() != null) {
            regionMapper.updateByPrimaryKey(region);
        }else {
            regionMapper.insert(region);
        }

    }


    public PageInfo<Region> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Region> list = regionMapper.queryForList(qo);
        return new PageInfo<Region>(list);
    }

    public List<Region> queryByParentId(RegionQueryObject qo) {
        return regionMapper.queryByParentId(qo);
    }

    public void changeState(Region region) {
        regionMapper.changeState(region);
    }

    public List<Region> queryAll(Integer state) {
        return regionMapper.selectAll(state);
    }
}
